package com.loong.system.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.global.dto.UserDTO;
import com.loong.system.common.forehead.param.DeleteFeedbackForeheadParam;
import com.loong.system.common.forehead.param.SystemFeedbackForeheadParam;
import com.loong.system.common.forehead.param.SystemFeedbackForeheadQueryParam;
import com.loong.system.common.forehead.result.SystemFeedbackForeheadResult;
import com.loong.system.handler.SystemFeedbackHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 处理前台用户反馈相关请求的controller
 * @Author: LiuQun
 * @Date: 2021/1/4 16:28
 */
@RestController
@RequestMapping("forehead/system/feedback")
public class SystemFeedbackForeheadController extends BaseForeheadController {

    @Resource
    private SystemFeedbackHandler feedbackHandler;

    /**
     * 新增用户反馈
     * @param feedbackParam 反馈参数
     * @return 响应的结果
     */
    @PostMapping("save")
    public Result saveFeedback(@RequestBody @Validated(value = {CommonInsert.class}) SystemFeedbackForeheadParam feedbackParam){
        feedbackParam.setId(null);
        UserDTO userDTO = super.getUserDTO();
        feedbackParam.setUserId(userDTO.getId());
        feedbackParam.setUserType(userDTO.getUserType());
        return handlerExecutor.execute(() -> feedbackHandler.foreheadSaveFeedback(feedbackParam) );
    }

    /**
     * 批量删除用户反馈
     * @param param 反馈id集合和用户id封装的参数
     * @return 响应的结果
     */
    @PostMapping("batchDelete")
    public Result batchDeleteFeedback(@RequestBody @Validated({CommonValidate.class})DeleteFeedbackForeheadParam param){
        Long userId = super.getUserDTO().getId();
        param.setUserId(userId);
        return handlerExecutor.execute(() -> feedbackHandler.foreheadBatchDeleteFeedback(param));
    }

    /**
     * 分页查询用户反馈
     * @param param 查询参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/feedbackList")
    public Result pageQueryFeedback(@RequestBody SystemFeedbackForeheadQueryParam param){
        UserDTO userDTO = super.getUserDTO();
        param.setUserId(userDTO.getId());
        param.setUserType(userDTO.getUserType());
        return handlerExecutor.execute(() -> feedbackHandler.foreheadPageQueryFeedback(param));
    }

    /**
     * 用户对回复的反馈进行评价
     * @param param 反馈参数
     * @return 响应的结果
     */
    @PostMapping("appraise/feedback")
    public Result appraiseFeedback(@RequestBody @Validated(value = {CommonValidate.class}) SystemFeedbackForeheadParam param){
        return handlerExecutor.execute(() -> feedbackHandler.foreheadAppraiseFeedback(param));
    }

    /**
     * 用户更新反馈
     * @param param 反馈参数
     * @return 响应的结果
     */
    @PostMapping("update")
    public Result updateFeedback(@RequestBody @Validated({CommonUpdate.class})SystemFeedbackForeheadParam param){
        return handlerExecutor.execute(() -> feedbackHandler.foreheadUpdateFeedback(param));
    }

}
